package com.zxr.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.zxr.common.annotation.Log;
import com.zxr.common.enums.BusinessType;
import com.zxr.system.domain.OrderItems;
import com.zxr.system.service.IOrderItemsService;
import com.zxr.common.core.controller.BaseController;
import com.zxr.common.core.domain.AjaxResult;
import com.zxr.common.utils.poi.ExcelUtil;
import com.zxr.common.core.page.TableDataInfo;

/**
 * 订单商品明细Controller
 * 
 * @author zxrproject
 * @date 2025-04-26
 */
@Controller
@RequestMapping("/system/items")
public class OrderItemsController extends BaseController
{
    private String prefix = "system/items";

    @Autowired
    private IOrderItemsService orderItemsService;

    @RequiresPermissions("system:items:view")
    @GetMapping()
    public String items()
    {
        return prefix + "/items";
    }

    /**
     * 查询订单商品明细列表
     */
    @RequiresPermissions("system:items:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderItems orderItems)
    {
        startPage();
        List<OrderItems> list = orderItemsService.selectOrderItemsList(orderItems);
        return getDataTable(list);
    }

    /**
     * 导出订单商品明细列表
     */
    @RequiresPermissions("system:items:export")
    @Log(title = "订单商品明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderItems orderItems)
    {
        List<OrderItems> list = orderItemsService.selectOrderItemsList(orderItems);
        ExcelUtil<OrderItems> util = new ExcelUtil<OrderItems>(OrderItems.class);
        return util.exportExcel(list, "订单商品明细数据");
    }

    /**
     * 新增订单商品明细
     */
    @RequiresPermissions("system:items:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存订单商品明细
     */
    @RequiresPermissions("system:items:add")
    @Log(title = "订单商品明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderItems orderItems)
    {
        return toAjax(orderItemsService.insertOrderItems(orderItems));
    }

    /**
     * 修改订单商品明细
     */
    @RequiresPermissions("system:items:edit")
    @GetMapping("/edit/{orderItemId}")
    public String edit(@PathVariable("orderItemId") Long orderItemId, ModelMap mmap)
    {
        OrderItems orderItems = orderItemsService.selectOrderItemsByOrderItemId(orderItemId);
        mmap.put("orderItems", orderItems);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单商品明细
     */
    @RequiresPermissions("system:items:edit")
    @Log(title = "订单商品明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderItems orderItems)
    {
        return toAjax(orderItemsService.updateOrderItems(orderItems));
    }

    /**
     * 删除订单商品明细
     */
    @RequiresPermissions("system:items:remove")
    @Log(title = "订单商品明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderItemsService.deleteOrderItemsByOrderItemIds(ids));
    }
}
